package Offer.q10_fib;

public class Solution {
    public static void main(String[] args) {
        Solution s = new Solution();
        // System.out.println(s.fib(3));
        s.fib(4);
    }

    public int fib(int n) {
        // long[] f = new long[n + 1];
        // 此题有特殊要求，需要取模，所以要加入一些设定
        final int MOD = 1000000007;
        if (n == 0) {
            return 0;
        }

        int p = 0, q = 0, r = 1;
        for (int i = 1; i < n; i++) {
            p = q;
            q = r;
            r = (p + q) % MOD;
        }

        return r;
    }
}
